package cn.ekuma.epos.datalogic.define.dao.shard;
import cn.ekuma.epos.db.table.shard.I_AddressEntityTable;
import com.openbravo.bean.shard.I_AddressEntity;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class AddressEntityDAOHelper {

	 public static TableDefinition getTable(I_Session s,String tableName){
	        return  new TableDefinition(s
	            , tableName
	            ,new Field[]{
	                new Field(I_AddressEntityTable.ID,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.PHONE2,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.FAX,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.ADDRESS,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.ADDRESS2,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.POSTAL,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.CITY,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.REGION,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.COUNTRY,Datas.STRING,Formats.STRING),
	                new Field(I_AddressEntityTable.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP)   
	        }
            , new int[] {0}
        );
	 }
	
	public static void writeInsertValues(DataWrite dp, I_AddressEntity obj,int start) throws BasicException {
		dp.setString(start, obj.getKey());
		dp.setString(start+1, obj.getPhone2());
        
        dp.setString(start+2, obj.getFax());
        dp.setString(start+3, obj.getAddress());
        dp.setString(start+4, obj.getAddress2());
        dp.setString(start+5, obj.getPostal());        
        dp.setString(start+6, obj.getCity());
        
        dp.setString(start+7, obj.getRegion());
        dp.setString(start+8, obj.getCountry());
        dp.setTimestamp(start+9, obj.getLastModified());
    }

    public static void readValues(DataRead dr,I_AddressEntity obj,int start) throws BasicException {
    	obj.setKey(dr.getString(start));
    	obj.setPhone2(dr.getString(start+1));
        
    	obj.setFax(dr.getString(start+2));
    	obj.setAddress(dr.getString(start+3));
    	obj.setAddress2(dr.getString(start+4));
    	obj.setPostal(dr.getString(start+5));        
    	obj.setCity(dr.getString(start+6));
        
    	obj.setRegion(dr.getString(start+7));
    	obj.setCountry(dr.getString(start+8));
    	obj.setLastModified(dr.getTimestamp(start+9));
    }
	
}
